package Operations;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class Delebook implements Ioperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        System.out.println("请输入你想删除的图书名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int pos = -1;
        for (int i = 0; i < bookList.getSize(); i++) {
            Book books = bookList.Getpos(i);
            if (name.equals(books.getBook_name())) {
                pos = i;
                break;
            }
        }
        if(pos==-1) {
            System.out.println("找不到此书");
        }
        for (int i = pos; i < bookList.getSize() - 1; i++) {
            Book book = bookList.Getpos(i+1);
            bookList.Setbook(book, i);
        }
        int curSize= bookList.getSize();
        bookList.setSize(curSize-1);
        bookList.Setbook(null, curSize-1);
        System.out.println("删除成功");
    }
}
